package zarelli.biff;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

/**
 *
 * @author guilherme
 */
public class Main extends Activity {

    private static final String TAG = "WebViewVideo.Main";
    private MyChromeClient webChromeCliente;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        webChromeCliente = new MyChromeClient(this, R.id.layout);

        WebView webView = (WebView) findViewById(R.id.webview);
        webView.setWebViewClient(new MyWebViewClient());
        webView.setWebChromeClient(webChromeCliente);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setPluginsEnabled(true);

        //webView.loadUrl("file:///android_asset/demo2/index.html");
        //webView.loadUrl("http://broken-links.com/tests/video/");
        //webView.loadUrl("http://dev.sencha.com/deploy/touch/examples/kitchensink/");
        webView.loadUrl("http://www.youtube.com/watch?v=JYWPdFCXOdU&feature=g-vrec&context=G2baf7aaRVAAAAAAAAAg");
    }

    @Override
    public void onBackPressed() {
        try {
            webChromeCliente.stopVideo();
        } catch (Exception e) {
            Log.e(TAG, ".onBackPressed", e);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuItem mi1 = menu.add(Menu.FIRST, 55, Menu.CATEGORY_ALTERNATIVE, "Sair");
        mi1.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == 55) {
            this.finish();
        }
        return super.onOptionsItemSelected(item);
    }
}
